package website.servlet;

import java.io.IOException;


import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;












import website.negocio.GestionOfertas;

/**
 * Servlet implementation class registrarOfertaServlet
 */
@WebServlet("/registrarOfertaServlet")
public class registrarOfertaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public registrarOfertaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		
		String nomOferta = request.getParameter("txtnombreOferta").toUpperCase();
		String FcOferta = request.getParameter("txtfechaCaducidad");
			
		java.sql.Date CfecOferta = java.sql.Date.valueOf(FcOferta);
		String DesOferta = request.getParameter("txtDescripcion").toUpperCase();
		String ubiOferta = request.getParameter("cboUbicacion").toUpperCase();
		
		String valor=request.getParameter("txtdescuento");
		int descOferta = Integer.parseInt(valor);
		double porDesOferta= (double)descOferta/100;
		
			
		GestionOfertas negocio = new GestionOfertas();
		try {
			
		
			
			String registro="Se realizo el registro de la oferta "+ nomOferta+" ...";
			negocio.insertar(nomOferta,CfecOferta,DesOferta,ubiOferta,porDesOferta);
					
			
			request.setAttribute("registro",registro);
			RequestDispatcher rd = request.getRequestDispatcher("ofertasAdministrador.jsp");
			//response.sendRedirect(request.getContextPath()	+ "/ofertasAdministrador.jsp");
			rd.forward(request, response);
						
			
		} catch (website.excepcion.DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}

		
		
		
		
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
